from django.db import models
from django.contrib.auth.models import AbstractUser


class MyUser(AbstractUser):
    """用户表"""
    username = models.CharField(verbose_name='用户名', max_length=20, null=True, blank=True)
    password = models.CharField(verbose_name='密码', max_length=128, null=True, blank=True)
    name = models.CharField(verbose_name='姓名', max_length=150, null=True, blank=True)
    mobile = models.CharField(verbose_name='联系方式', max_length=100, null=True, blank=True)
    email = models.EmailField(verbose_name='邮箱地址', max_length=150, unique=True)

    create_time = models.DateTimeField('创建时间', auto_now_add=True, blank=True, null=True)
    update_time = models.DateTimeField('更新时间', auto_now=True, blank=True, null=True)

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = ['name']

    class Meta:
        db_table = 'auth_user'
        verbose_name = '用户表'
        verbose_name_plural = verbose_name
        ordering = ['-create_time']

    def __str__(self):
        return self.email
